package com.mall.utils;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.io.Serializable;
import java.util.List;

/**
 * @Author ManySisters
 * @create 2023-02-10 17:07
 */

/**
 * 用户分页查询结果
 */
@Data
@NoArgsConstructor
@AllArgsConstructor
public class PageResult implements Serializable {
    private Long total;//总条数
    private Long totalPage;//总页数
    private Long pageSize;//每页条数
    private Long pageNum;//当前页
    private Object list;//数据

    public static PageResult init(Long total, Long pageSize, Long pageNum, List list){
        long totalPage = total % pageSize == 0 ? total/pageSize : total/pageSize + 1;

        return new PageResult(total, pageNum, pageSize, totalPage, list);
    }

    public static PageResult init(Page page){

        long totalPage = page.getTotal() % page.getSize() == 0 ? page.getTotal()/page.getSize() : page.getTotal()/page.getSize() + 1;
        return new PageResult(page.getTotal(), page.getCurrent(), page.getSize(), totalPage, page.getRecords());
    }
}